package com.darren.framework.controller;


import com.darren.framework.utils.Constant;
import net.sf.ehcache.CacheManager;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import redis.clients.jedis.JedisPool;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


public class BaseController {

    protected Logger logger = LogManager.getLogger(getClass());

    protected static final Integer pageSize = Constant.PAGE_SIZE;
    protected static final String pageSizeString = Constant.PAGE_SIZE_STRING;

    @Autowired
    protected HttpServletRequest request; //自动注入request

    /**
     * 获取当前请求的 HttpServletRequest 对象
     *
     * @return
     */
    protected HttpServletRequest getRequest() {
        return ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getRequest();
    }

    /**
     * 获取当前请求的 HttpServletResponse 对象
     *
     * @return
     */
    protected HttpServletResponse getResponse() {
        return ((ServletRequestAttributes) (RequestContextHolder.currentRequestAttributes())).getResponse();
    }

    @Autowired
    protected CacheManager ehCacheManager;

    @Autowired
    protected RedisCacheManager redisCacheManager;

    @Autowired
    protected JedisPool jedisPool;//注入JedisPool

    public static final String SUCCESS = "success";

    public static final String ERROR = "error";

}
